package com.sina.interfaces.domain.user;

import com.sina.interfaces.core.domain.Domain;
import org.hibernate.annotations.*;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.time.LocalDateTime;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 段浩杰   2017-09-21-9:22
 */
@Entity
@Table(name = "in_user")
@DynamicInsert
@DynamicUpdate
public class User extends Domain {


    public User(Long id, String name, String lastIp, LocalDateTime createTime, UserSex userSex, String phone, String email, Status status) {
        this.id = id;
        this.name = name;
        this.lastIp = lastIp;
        this.createTime = createTime;
        this.userSex = userSex;
        this.phone = phone;
        this.email = email;
        this.status = status;
    }

    public User() {
    }

    @Id
    @Column(name = "id", updatable = false)
    @GenericGenerator(name = "sequence_id", strategy = "com.sina.interfaces.core.sequence.IdGenerator")
    @GeneratedValue(generator = "sequence_id")
    @Min(1)
    private Long id;


    @Column(name = "name")
    private String name;


    @Column(name = "password")
    private String password;


    @Column(name = "lastip")
    @Min(4)
    @Max(12)
    private String lastIp;


    @Column(name = "create_time", updatable = false)
    @ColumnDefault("CURRENT_TIMESTAMP")
    @CreationTimestamp
    private LocalDateTime createTime;

    @Column(name = "phone", length = 15)
    @Length(min = 11, max = 11)
    private String phone;

    @Column(name = "email", length = 20)
    private String email;

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 10)
    private Status status;

    @Enumerated(EnumType.STRING)
    @Column(name = "user_sex", nullable = false, length = 2, updatable = false)
    private UserSex userSex;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getLastIp() {
        return lastIp;
    }

    public void setLastIp(String lastIp) {
        this.lastIp = lastIp;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public UserSex getUserSex() {
        return userSex;
    }

    public void setUserSex(UserSex userSex) {
        this.userSex = userSex;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }
}
